<?php
/**
 * Project: Recipe
 * File: FoodNutritionsAction.class.php
 * Author: Xnfy520@gmail.com
 * Date: 12-5-7
 * Time: 上午9:23
 */

class FoodNutritionsAction extends CommonAction{

	/**
	 * 指向修改食材营养界面
	 */
	function edit(){
		if(!empty($_GET['sid']) || !empty($_GET['cid']) || !empty($_GET['aid'])){
			if(isset($_GET['sid']) || isset($_GET['cid']) || isset($_GET['aid'])){

				$foodarticle = D('FoodArticle');
				$map['sectionid'] = $_GET['sid'];
				$map['categoryid'] = $_GET['cid'];
				$map['id'] = $_GET['aid'];
				$foodarticleinfo = $foodarticle->where($map)->relation(true)->find();
				$this->assign('data', $foodarticleinfo);

				$foodnutritions = M('FoodNutritions');
				$maps['sectionid'] = $_GET['sid'];
				$maps['categoryid'] = $_GET['cid'];
				$maps['articleid'] = $_GET['aid'];
				$datas = $foodnutritions->where($maps)->find();
				$this->assign('datas', $datas);

				$this->display();
			}else{
				$this->error('异常操作');
			}
		}else{
			$this->error('异常操作');
		}
	}

	/**
	 * 修改食材营养
	 */
	function update(){
		if(isset($_POST['id']) && !empty($_POST['id'])){
			$foodnutritions = D('FoodNutritions');
			if($data = $foodnutritions->create()){
					$foodnutritions->save();
					$this->success('修改食材营养成功');
			}else{
				$this->error($foodnutritions->getError());
			}
		}else{
			$this->error('异常操作');
		}
	}

}